package com.atguigu.day22.clazz04;

import org.junit.Test;

import java.lang.reflect.Modifier;
import java.util.Scanner;

public class ReflectTest {

    public static void main(String[] args) throws Exception{
        Scanner in = new Scanner(System.in);
        System.out.println("请问你喜欢什么小动物");
        String message  =in.next();
        Class<?> aClass = Class.forName(message);
        Object o = aClass.newInstance();
        System.out.println("o = " + o);

    }

    @Test
    public void test03(){
        Dog dog = new Dog();
        Cat cat = new Cat();
    }

    @Test
    public void test02(){
        Class<Monkey> monkeyClass = Monkey.class;
        int modifiers = monkeyClass.getModifiers();
        System.out.println("modifiers = " + modifiers);//1 17
        String str = Modifier.toString(modifiers);
        System.out.println("str = " + str);
    }

    @Test
    public void test01(){
        //1.获取运行时类对象
        Class<Dog> dogClass = Dog.class;

        Class<? super Dog> superclass = dogClass.getSuperclass();

        System.out.println("superclass = " + superclass);//class com.atguigu.clazz04.Animal

        //获取实现的接口
        Class<?>[] interfaces = dogClass.getInterfaces();
        for (Class<?> anInterface : interfaces) {
            System.out.println("anInterface = " + anInterface);
        }

    }
}
